#pragma once

#include "DurationObservation.h"

#include "NamedElement.h"

namespace uml {

DurationObservation::DurationObservation(const QString& umlType)
    : Observation(umlType) {}

void DurationObservation::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Observation::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(events_, "events", json, errorList);
    JsonSerializable::fromJsonArray(firstEvents_, "firstEvents", json, errorList);
}

void DurationObservation::toJson(QJsonObject& json) {
    Observation::toJson(json);
    JsonSerializable::toJsonArray(events_, "events", json);
    JsonSerializable::toJsonArray(firstEvents_, "firstEvents", json);
}

/// <summary>
/// events getter
/// The DurationObservation is determined as the duration between the entering or
/// exiting of a single event Element during execution, or the entering/exiting of
/// one event Element and the entering/exiting of a second.
/// </summary>
vector<shared_ptr<NamedElement>>& DurationObservation::events() {
    return events_;
}

/// <summary>
/// firstEvents getter
/// The value of firstEvent[i] is related to event[i] (where i is 1 or 2). If
/// firstEvent[i] is true, then the corresponding observation event is the first
/// time instant the execution enters event[i]. If firstEvent[i] is false, then the
/// corresponding observation event is the time instant the execution exits
/// event[i].
/// </summary>
vector<bool>& DurationObservation::firstEvents() {
    return firstEvents_;
}

} // namespace uml
